package com.musiklegal;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class BannerParser extends DefaultHandler{
	
		
		
		boolean intitle=false,
		inmedia=false,
		inurl=false;
		StringBuffer buffer;
		BannerData bannerData;
		
		static class BannerData
		{
			String title;
			String media;
			String address;
		}

		BannerParser()
		{
			buffer= new StringBuffer();
		}
		
		
		public void startDocument() throws SAXException
		{
			bannerData = new BannerData();
		}
		
		public void endDocument() throws SAXException
		{
			
		}

		public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException
		{
			if(localName.equals("title"))
			{
				intitle=true;
			}
			else if(localName.equals("media"))
			{
				inmedia=true;
			}
			else if(localName.equals("url"))
			{
				inurl = true;
			}
			
		}
		
		
		public void endElement(String namespaceURI, String localName, String qName)
		throws SAXException 
		{
			if(localName.equals("title"))
			{
				intitle=false;
				bannerData.title=buffer.toString();
				buffer = new StringBuffer();
			}
			else if(localName.equals("media"))
			{
				inmedia=false;
				bannerData.media=buffer.toString();
				buffer = new StringBuffer();
			}
			else if(localName.equals("url"))
			{
				inurl = false;
				bannerData.address=buffer.toString();
				buffer = new StringBuffer();
			}
			
		}
		
		 public void characters(char ch[], int start, int length) 
		 {
			 buffer.append(new String(ch,start,length));
			 
		 }

}
